<extend name="Layout/ins_page" />
<block name="content">
	<input type="hidden" name="ajax" id="ajax" value="1">
	<select name="dept_list" id="dept_list" class="hidden">
		<option value="0">根节点</option>
		{:fill_option($dept_list)}
	</select>
	{:W('PageHeader/simple',array('name'=>'部门管理'))}
	<div class="oprator-panel">
		<div class="split"></div>
		<a id="btn_add" class="btn">新增</a>
		<a id="btn_save"  class="btn">保存</a>
		<span class="l">|</span>
		<a id="btn_del"  class="btn btn-del">删除</a>
	</div>
	<!-- 功能操作区域结束 -->
	<div class="sub-frame">
		<div class="sub-sidebar gray" style="max-height: 526px;overflow-y: auto;">
			<?php echo $menu ?>
		</div>
		<div class="sub-content gray">
			<form id="form_data" name="form_data" method="post" >
				<input type="hidden" name="id" id="id">
				<input type="hidden" name="opmode" id="opmode" value="">
				<div class="layui-sub-form-item hidden">
					<label class="layui-form-label" for="dept_no">编码*：</label>
					<div class="layui-input-block">
						<input class="layui-input" type="text" id="dept_no" name="dept_no" >
					</div>
				</div>
				<div class="layui-sub-form-item">
					<label class="layui-form-label" for="name">名称*：</label>
					<div class="layui-input-block">
						<input class="layui-input" type="text" id="name" name="name" check="required" info="请输入名称">
					</div>
				</div>
				<div class="layui-sub-form-item">
					<label class="layui-form-label" for="short">简称*：</label>
					<div class="layui-input-block">
						<input class="layui-input" type="text" id="short" name="short" check="required" info="请输入简称">
					</div>
				</div>
				<div class="layui-sub-form-item">
					<label class="layui-form-label" for="dept_name">上级部门*：</label>
					<div class="layui-input-block">
						<input name="dept_name" class="layui-input" id="dept_name" type="text" readonly="readonly" info="请选择上级部门" check="required"/>
						<input name="pid" id="pid" type="hidden" info="请选择上级部门" check="required" />
						<a class="add-on" id="btn_select_pid">选择</a>
					</div>
				</div>
				<div class="layui-sub-form-item">
					<label class="layui-form-label" for="dept_grade_id">部门级别*：</label>
					<div class="layui-input-block x-select">
						<select name="dept_grade_id" id="dept_grade_id" class="layui-input" info="请选择部门级别" check="required">
							<option value="">选择部门级别</option>
							{:fill_option($dept_grade_list)}
						</select>
					</div>
				</div>
				<div class="layui-sub-form-item">
					<label class="layui-form-label" for="sort">排序：</label>
					<div class="layui-input-block col-10">
						<input class="layui-input" type="text" id="sort" name="sort" >
					</div>
				</div>
				<div class="layui-sub-form-item">
					<label class="layui-form-label" for="is_del">状态*：</label>
					<div class="layui-input-block x-select col-10">
						<select   name="is_del" id="is_del" class="layui-input">
							<option value="0">启用</option>
							<option value="1">禁用</option>
						</select>
					</div>
				</div>
				<div class="layui-sub-form-item col-xs-12">
					<label class="layui-form-label" for="remark" >其他：</label>
					<div class="layui-input-block" >
						<textarea class="layui-textarea" name="remark" id="remark" rows="5" class="col-xs-12" ></textarea>
					</div>
				</div>
			</form>
		</div>
	</div>
</block>
<block name="js">
	<script type="text/javascript">
		layui.use(['global'], function() {
			function showdata(result) {
				for (var s in result.data) {
					set_val(s, result.data[s]);
				}
				$("#dept_name").val($("#dept_list option[value='" + $("#pid").val() + "']").text());
				$("#opmode").val("edit");
			};

			$('.sub-sidebar .tree_menu a').on('click', function() {
				$(".sub-sidebar .tree_menu a.active").removeClass("active");
				$this = $(this);
				$this.addClass("active");

				node = $this.attr('node');
				$.getJSON("{:U('read')}", 'id=' + node, function(ret) {
					showdata(ret);
				});
				return false;
			});

			$("#btn_add").on('click', function() {
				winopen("{:U('add')}", 560, 470);
			});

			$("#btn_save").on('click', function() {
				send_form("form_data", "{:U('save')}", "{:U('index')}", function(ret) {
					if (ret.status) {
						layer.msg(ret.info, {
							time : 1200
						}, function() {
							location.reload(true);
						});
					} else {
						layer.msg(ret.info);
						return false;
					}
				});
			});

			$('#btn_del').on('click', function() {
				if ($(".sub-sidebar a.active").length == 0) {
					layer.msg('请选择要删除的部门');
					return false;
				}
				if ($(".sub-sidebar a.active").parent().find(".tree_menu").html() != undefined) {
					layer.msg('有子部门不能删除');
					return false;
				}
				//信息框-例2
				layer.msg('确定要删除吗?', {
					time : 0,
					btn : ['确定', '取消'],
					yes : function(index) {
						var vars = $("#form_data").serialize();
						send_ajax("{:U('del')}", vars, function(ret) {
							if (ret.status) {
								layer.msg(ret.info, function() {
									location.reload(true);
								});
							}
						});
					},
					no : function(index) {
						layer.close(index);
					}
				});
			});

			$('#btn_select_pid').on('click', function() {
				winopen("{:U('winpop')}", 560, 470);
			});
		});
	</script>

</block>